<html>

<head>
<?php

if ($_GET[id]) {

	include "../includes/constants.php";
	include "../includes/functions.php";

	$query = "SELECT * FROM items WHERE id=" . $_GET[id];
	$result = mysql_query($query,$db);
};

?>

<title><?php if ($db_row = @mysql_fetch_array($result)) {echo $db_row[Name];};?></title>

<script src="../includes/functions.js"></script>

</head>

<body>

<?php

if (!$_GET["id"]) {
	die("<form name=\"NoID\" method=\"GET\" action=\"\">Enter ID: <input type=\"text\" name=\"id\" size=\"2\"><br></form>\n");
};

if ($db_row) {
	// Item Icon (right-aligned)
	echo "<img src=\"../images/icons-items/" . $db_row[icon] . ".gif\" alt=\"" . $db_row[Name] . "\" align=\"right\">\n";

	// Item Name
	echo $db_row[Name] . "<br>\n";

	// Magic, Lore, No Trade, or Artifact
	if ($db_row[magic] == 1) echo "MAGIC ITEM  ";
	if ($db_row[loregroup] != 0) echo "LORE ITEM  ";
	if ($db_row[nodrop] == 0) echo "NO TRADE  ";
	if ($db_row[norent] == 0) echo "TEMPORARY  ";
	if ($db_row[artifactflag] == 1) echo "ARTIFACT  ";
	if ($db_row[augtype] > 0) echo "AUGMENTATION  ";

// Line break for item type
	if ($db_row[magic] == 1 || 
		$db_row[loregroup] != 0 || 
		$db_row[nodrop] == 0 || 
		$db_row[norent] == 0 || 
		$db_row[artifactflag] == 1 ||
		$db_row[augtype] > 0
	) echo "<br>\n";

	// Lore Group
//	if ($db_row["loregroup"] == 1) 

	// Slot(s)
	if ($db_row[slots] > 0) {
		echo "Slot: ";
		foreach ($Slots as $key => $value) {if ($db_row[slots] & $key) echo strtoupper($value) . " ";};
		echo "<br>\n";
	};
	
	// Charges
	if ($db_row[maxcharges] > 0) {
		echo "EXPENDABLE Charges: ";
		if ($_GET[charges] != "") {echo $_GET[charges];}
		else {echo $db_row[maxcharges];};
		echo "<br>\n";
	};

	// Item type/Skill
	echo "Skill: " . $ItemType[$db_row[itemtype]] . " ";

	// Atk Delay
	if ($db_row[delay] > 0) echo "Atk Delay: " . $db_row[delay];

// Line Break for Skill, Atk Delay
	echo "<br>\n";

	// Damage
	if ($db_row[damage] > 0) echo "DMG: " . $db_row[damage] . " ";

	// Damage Bonus
	// if ($db_row[delay]) echo "Dmg Bonus: ";

	// AC
	if ($db_row[ac] > 0) echo "AC: " . $db_row[ac];

// Line break for DMG/Dmg Bonus/AC line
	if ($db_row[damage] != 0 || 
	//	$db_row[delay] != 0 || 
		$db_row[ac] != 0
	) echo "<br>\n";
	
	// Elemental Damage
	if ($db_row[elemdmgtype] > 0 && $db_row[elemdmgamt] > 0) echo $ElemDmgType[$db_row[elemdmgtype]] . " DMG: " . $db_row[elemdmgamt] . "<br>\n";
	
	// Bane Damage
	if (($db_row[banedmgbody] > 0) || ($db_row[banedmgrace] > 0)) {
		echo "Bane DMG: ";
		echo $db_row[banedmgbody] . ", " . $db_row[banedmgrace] . " ";
		echo $db_row[banedmgamt] + $db_row[banedmgraceamt];
		echo "<br>\n";
	};

	// Skill Mod
	if ($db_row[skillmodtype] > 0 && $db_row[skillmodtype] < 255) {
		echo "Skill Mod: " . $Skills[$db_row[skillmodtype]] . " ";
		if ($db_row[skillmodvalue] > 0) {echo "+" . $db_row[skillmodvalue];}
		elseif ($db_row[skillmodvalue] < 0) {echo "-" . $db_row[skillmodvalue];};
		echo " %<br>\n";
	};

	// Proc Effect
	if ($db_row[proceffect] > 0) {
		// Set to show spell description at the bottom
		$ItemEffects[proceffect] = $db_row[proceffect];
		echo "Effect: " . GetSpellName($db_row[proceffect]) . " (";
		echo "Combat";
		echo ")<br>\n";
	};

	// Worn Effect
	if ($db_row[worneffect] > 0) {
		// Set to show spell description at the bottom
		$ItemEffects[worneffect] = $db_row[worneffect];
		echo "Effect: " . GetSpellName($db_row[worneffect]) . " (";
		if ($db_row[worntype] == 2) echo "Worn";
		echo ")<br>\n";
	};

	// Effect
	if ($db_row[clickeffect] > 0) {
		// Set to show spell description at the bottom
		$ItemEffects[clickeffect] = $db_row[clickeffect];
		echo "Effect: " . GetSpellName($db_row[clickeffect]) . " (";
		if ($db_row[casttime] > 0) {
			$casttime = $db_row[casttime]/1000;
			if (($db_row[casttime] % 1000) == 0) $casttime .= ".0";
		} elseif ($db_row[casttime] == 0) {
			$casttime = "Instant";
		};
		switch ($db_row[clicktype]) {
			case 0: 
				echo "Combat"; break;
			case 1: 
				echo "Casting Time: " . $casttime; break;
			case 2: 
				echo "Worn"; break;
			case 3: 
				echo "Casting Time: " . $casttime; break;
			case 4: 
				echo "Must Equip. Casting Time: " . $casttime; break;
			case 5: 
				echo "Casting Time: " . $casttime; break;
		};
		echo ")<br>\n";
		if ($db_row[recastdelay] > 0) {
			echo "Recast Delay: ";
			if ($db_row[recastdelay] < 60) {echo $db_row[recastdelay] . " seconds, ";}
			elseif (($db_row[recastdelay] >= 60) && ($db_row[recastdelay] < 3600)) {echo $db_row[recastdelay]/60 . " minutes, ";}
			elseif (($db_row[recastdelay] >= 3600)) {echo $db_row[recastdelay]/3600 . " hours, ";};
			echo "Recast Type: " . $db_row[recasttype] . "<br>\n";
		};
	};

	// Focus
	if ($db_row[focuseffect] > 0) {
		// Set to show spell description at the bottom
		$ItemEffects[focuseffect] = $db_row[focuseffect];
		echo "Focus: " . GetSpellName($db_row[focuseffect]) . " ";
		echo "<br>\n";
	};

	echo OutputItemStats(astr,"STR");
	echo OutputItemStats(adex,"DEX");
	echo OutputItemStats(asta,"STA");
	echo OutputItemStats(acha,"CHA");
	echo OutputItemStats(awis,"WIS");
	echo OutputItemStats(aint,"INT");
	echo OutputItemStats(aagi,"AGI");
	echo OutputItemStats(hp,"HP");
	echo OutputItemStats(mana,"MANA");
	echo OutputItemStats(endur,"Endurance");

// Line break for stats
	if (OutputItemStats(astr,"STR") || 
		OutputItemStats(adex,"DEX") || 
		OutputItemStats(asta,"STA") || 
		OutputItemStats(acha,"CHA") || 
		OutputItemStats(awis,"WIS") || 
		OutputItemStats(aint,"INT") || 
		OutputItemStats(aagi,"AGI") || 
		OutputItemStats(hp,"HP") || 
		OutputItemStats(mana,"MANA") || 
		OutputItemStats(endur,"Endurance")
	) echo "<br>\n";

	echo OutputItemStats(fr,"SV FIRE");
	echo OutputItemStats(dr,"SV DISEASE");
	echo OutputItemStats(cr,"SV COLD");
	echo OutputItemStats(mr,"SV MAGIC");
	echo OutputItemStats(pr,"SV POISON");

// Line break for stats
	if (OutputItemStats(fr,"SV FIRE") || 
		OutputItemStats(dr,"SV DISEASE") || 
		OutputItemStats(cr,"SV COLD") || 
		OutputItemStats(mr,"SV MAGIC") || 
		OutputItemStats(pr,"SV POISON")
	) echo "<br>\n";

	if (OutputItemStats(attack)) echo OutputItemStats(attack) . "<br>\n";
	if (OutputItemStats(regen)) echo OutputItemStats(regen,"Regeneration") . "<br>\n";
	if (OutputItemStats(manaregen)) echo OutputItemStats(manaregen,"Mana Regeneration") . "<br>\n";
	if (OutputItemStats(enduranceregen)) echo OutputItemStats(enduranceregen,"Endurance Regeneration") . "<br>\n";
	if (OutputItemStats(damageshield)) echo OutputItemStats(damageshield,"Damage Shield") . "<br>\n";
	echo OutputItemStats(combateffects,"Combat Effects");
	echo OutputItemStats(shielding,"","%");
	echo OutputItemStats(spellshield,"Spell Shield","%");
	echo OutputItemStats(avoidance);
	echo OutputItemStats(accuracy);
	echo OutputItemStats(stunresist,"Stun Resist","%");
	echo OutputItemStats(strikethrough,"","%");
	
	// Line break for Shielding, Avoidance, Accuracy, etc
	if (OutputItemStats(combateffects) ||
		OutputItemStats(shielding) ||
		OutputItemStats(spellshield) ||
		OutputItemStats(avoidance) ||
		OutputItemStats(accuracy) ||
		OutputItemStats(stunresist) ||
		OutputItemStats(strikethrough) 
	) echo "<br>\n";
	
	// Dot Shielding
	if (OutputItemStats(dotshielding)) echo OutputItemStats(dotshielding) . "<br>\n";
	
	// Haste
	if ($db_row[haste] > 0) echo "Haste: " . $db_row["haste"] . "%<br>\n";

	// Bard Instrument Modifier
	if ($db_row[bardtype] > 0 || $db_row[bardvalue] > 0) echo $BardTypes[$db_row[bardtype]] . ": " . $db_row[bardvalue] . "<br>\n";

	// Skill Add DMG
	if ($db_row[extradmgskill] != 0 || $db_row[extradmgamt] != 0) echo $Skills[$db_row[extradmgskill]] . " DMG: +" . $db_row[extradmgamt] . "<br>\n";

	// Recommended Level
	if ($db_row[reclevel] > 0) echo "Recommended level of " . $db_row["reclevel"] . ". ";

	// Required Level
	if ($db_row[reqlevel] > 0) echo "Required level of " . $db_row[reqlevel] . ". ";

// Line break for Level requirements
	if ($db_row[reclevel] > 0 || $db_row[reqlevel] > 0) echo "<br>\n";

	// Weight
	echo "WT: " . round($db_row[weight] / 10, 1) . " ";
	
	// Range on thrown items
	if ($db_row["range"] != 0) echo "Range: " . $db_row["range"] . " ";

	// Size
	echo "Size: " . strtoupper($ItemSize[$db_row[size]]) . " ";
	
	// Bag Weight Reduction
	if ($db_row[bagwr] != 0) echo "Weight Reduction: " . $db_row[bagwr] . "% ";
	
	// Line break
	echo "<br>\n";
	
	// Bag Capacity
	if ($db_row[bagslots] != 0) echo "Capacity: " . $db_row[bagslots] . " ";
	
	// Bag Size Capacity
	if ($db_row[bagsize] != 0) echo "Size Capacity: " . strtoupper($ItemSize[$db_row[bagsize]]) . " ";
	
	// Line Break for Bag Capacity & Bag Size Capacity
	if ($db_row[bagslots] != 0 || $db_row[bagsize] != 0) echo "<br>\n";

	// Class(es)
	echo "Class: ";
	if ($db_row[classes] == 65535) echo "ALL ";
	elseif ($db_row[classes] == 0) echo "NONE ";
	else {foreach ($ClassesShort as $key => $value) if ($db_row[classes] & pow(2, $key - 1)) echo $value . " ";};
	echo "<br>\n";

	// Race(s)
	echo "Race: ";
	if (($db_row[races] == 32767) || ($db_row[races] == 65535)) {echo "ALL";}
	elseif ($db_row[races] == 0) {echo "NONE";}
	else {foreach ($Races as $key => $value) {if ($db_row[races] & $key) echo $value . " ";};};
	echo "<br>\n";

	// Augments (Slots 1-5)
	for ($x = 1; $x <= 5; $x++) {
		if ($db_row["augslot{$x}type"] > 0 || $_GET["augslot{$x}"] > 0) {
			echo "Slot " . $x . ", Type " . $db_row["augslot{$x}type"] . ": ";
			if ($_GET["augslot{$x}"] == 0) {echo "empty";}
			else {GetItemName($_GET["augslot{$x}"]);};
			echo "<br>\n";
			};
	};
	
	// Spell Information
	if ($ItemEffects) {
		foreach ($ItemEffects as $Key => $Value) {
			echo "<br>\n";
			echo GetSpellName($Value) . "<br>\n";
			echo "<br>\n";
			echo "Spell Effect: " . GetSpellText($Value) . "<br>\n";
		};
	};

	// Item Information
	if ($db_row[charmfile] != "") {
		echo "<br>\nItem Information:<br>\n";
		$query_charmfile = "SELECT txtfile FROM books WHERE name='" . $db_row[charmfile] . "'";
		$result_charmfile = mysql_query($query_charmfile,$db);
		$db_row_charmfile = mysql_fetch_array($result_charmfile);
		echo $db_row_charmfile[txtfile] . "<br>\n";
	};

} else {
	echo "<form name=\"NoID\" method=\"GET\" action=\"\">Enter ID: <input type=\"text\" name=\"id\" size=\"2\"><br></form>\n";
};


?>

</body>

</html>